﻿using System;
using System.Windows.Forms;
using DevExpress.XtraEditors.DXErrorProvider;

namespace ContractManager.Common.Class
{
    public  class ControlRule 
    { 
        public Control control;
         public ValidationRule rule; 

        public ControlRule (Control control, ValidationRule rule) 
        { 
            this.control =control;
             this.rule = rule; 
        } 

       
        public  static ConditionValidationRule NotEmpty() 
        { 
            ConditionValidationRule rule = new ConditionValidationRule (); 
            rule.ConditionOperator = ConditionOperator.IsNotBlank; 
            rule.ErrorText = "The value is not allowed to be empty!";
             return rule; 
        } 

        
        public  static ConditionValidationRule NoLessNumber ( decimal number) 
        { 
            ConditionValidationRule rule = new ConditionValidationRule (); 
            rule.ConditionOperator = ConditionOperator.GreaterOrEqual; 
            rule.ErrorText = String.Format(" This value can not be less than {0}! " , number); 
            rule.Value1 = number;
             return rule; 
        } 

       
        public  static ConditionValidationRule GreaterNumber ( decimal number) 
        { 
            ConditionValidationRule rule = new ConditionValidationRule (); 
            rule.ConditionOperator = ConditionOperator.Greater; 
            rule.ErrorText = String.Format(" This value must be greater than {0}! " , number); 
            rule.Value1 = number;
             return rule; 
        } 

       
        public  static ConditionValidationRule BetweenNumbers ( decimal small, decimal big) 
        { 
            ConditionValidationRule rule = new ConditionValidationRule (); 
            rule.ConditionOperator = ConditionOperator.Between; 
            rule.ErrorText = String.Format(" This value can not be less than {0} {1} and can not be greater! " , small, big); 
            rule.Value1 = small; 
            rule.Value2 = big;
             return rule; 
        } 

       
        public  static ConditionValidationRule NoLessDate (DateTime startTime) 
        { 
            ConditionValidationRule rule = new ConditionValidationRule (); 
            rule.ErrorText = String.Format(" end time can not be less than the start time! " ); 
            rule.ConditionOperator = ConditionOperator.GreaterOrEqual; 
            rule.Value1 = startTime;
             return rule; 
        }


        public static ConditionValidationRule BetweenDate(DateTime small, DateTime big)
        {
            ConditionValidationRule rule = new ConditionValidationRule();
            rule.ConditionOperator = ConditionOperator.Between;
            rule.ErrorText = String.Format(" This value can not be less than {0} {1} and can not be greater! ", small, big);
            rule.Value1 = small;
            rule.Value2 = big;
            return rule;
        } 


        public  static CustomRuleByRegex AddValueRex ( String strRex, bool isnotblank) 
        { 
            CustomRuleByRegex rule = new CustomRuleByRegex (strRex, isnotblank); 
            rule.ErrorText = " input format is incorrect, please re-enter! " ;
             return rule; 
        } 
    }
}
